package epoch.game.core.distr.call;

import java.io.IOException;

import epoch.game.core.serialize.ISerializable;
import epoch.game.core.serialize.IStreamReader;
import epoch.game.core.serialize.IStreamWriter;

/**
 * 远程调用结点信息
 */
public class CallPoint implements ISerializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/** 节点id */
	public int nodeId;
	/** 线程id */
	public int portId;
	/** 回调函数Id */
	public long callbackId;
	public boolean isActor;
	/** 调用方信息，供调试用 */
	public String callerInfo;
	
	/**
	 * 构造函数
	 */
	public CallPoint() {

	}
	
	/**
	 * 构造函数
	 * @param nodeId
	 * @param portId
	 * @param servId
	 */
	public CallPoint(int nodeId, int portId, long callbackId, boolean isActor) {
		this.nodeId = nodeId;
		this.portId = portId;
		this.callbackId = callbackId;
		this.isActor = isActor; // todolv下面远程没处理
		this.callerInfo = "";
	}

	
	@Override
	public String toString() {
		return new StringBuilder()
					.append("nodeId:").append(nodeId)
					.append("portId:").append(portId)
					.append("callbackId:").append(callbackId)
					.append("callerInfo:").append(callerInfo)
					.toString();
	}

	@Override
	public void readFrom(IStreamReader reader) throws IOException {
		nodeId = reader.readInt();
		portId = reader.readInt();
		callbackId = reader.readLong();
		callerInfo = reader.readString();
	}

	@Override
	public void writeTo(IStreamWriter writer) throws IOException {
		writer.writeInt(nodeId);
		writer.writeInt(portId);
		writer.writeLong(callbackId);
		writer.writeString(callerInfo);
	}
}
